//获取本地文件目录
import 'dart:io';

import 'package:path_provider/path_provider.dart';

Future<File> getLocalDocumentFile() async {
  final dir = await getApplicationDocumentsDirectory();
  return File('${dir.path}/str.txt');
}

/// 获取临时目录文件
Future<File> getLocalTemporaryFile() async {
  final dir = await getTemporaryDirectory();
  return File('${dir.path}/str.txt');
}

/// 获取应用程序目录文件
Future<File> getLocalSupportFile() async {
  final dir = await getApplicationSupportDirectory();
  return File('${dir.path}/str.txt');
}

/// 写入本地数据
Future<void> writeLocalString(String str) async {
  final file = await getLocalDocumentFile();
  await file.writeAsString(str);
}

//写入临时数据
Future<void> writeTemporaryString(String str) async {
  final file = await getLocalTemporaryFile();
  await file.writeAsString(str);
}

//写入应用程序目录
Future<void> writeLocalSupportString(String str) async {
  final file = await getLocalSupportFile();
  await file.writeAsString(str);
}

/// 读取值
Future<String?> readLocalString() async {
  String? result;
  try {
    final file = await getLocalDocumentFile();
    result = await file.readAsString();
  } catch (e) {}
  return result;
}

Future<String?> readLocalTemporaryString() async {
  String? result;
  try {
    final file1 = await getLocalTemporaryFile();
    final result1 = await file1.readAsString();
    print("result1-----$result1");
  } catch (e) {}
  return result;
}

Future<String?> readLocalSupportString() async {
  String? result;
  try {
    final file2 = await getLocalSupportFile();
    final result2 = await file2.readAsString();
  } catch (e) {}
  return result;
}
